#coding: utf-8

from django.db import models
from django.contrib.auth.models import User
from utilities import truncate_zhwords

# Create your models here.

class UserCfg(models.Model):
    user = models.ForeignKey(User, verbose_name=u'用户')
    mail_notify = models.BooleanField(u'是否使用邮件提醒', default=False)
    is_today_onduty = models.BooleanField(u'是否今天值班', default=False)

class Restaurant(models.Model):
    TYPE_CHOICE = (
        ('yue', u'粤菜'),
        ('snack', u'快餐'),
        ('chuang', u'川菜'),
        ('xiang', u'湘菜'),
        ('dongbei', u'东北菜'),
        ('qingzhen', u'新疆/清真'),
        ('other', u'其它'),
    )
    
    name = models.CharField(u'餐馆名', max_length=32)
    course_type = models.CharField(u'菜系', max_length=32, choices=TYPE_CHOICE)
    address = models.CharField(u'地址', max_length=128)
    phone = models.CharField(u'电话', max_length=32)
    img = models.ImageField(u'图片',upload_to='photos/%Y/%m/%d', blank=True)
    
    class Meta:
        verbose_name = u'餐馆'
        verbose_name_plural = u'餐馆'
        
    def __unicode__(self):
        return u"%s"%unicode(self.name)
        
        
class Course(models.Model):
    name = models.CharField(u'菜名', max_length=32)
    resta = models.ForeignKey(Restaurant, verbose_name = u'餐馆')
    price = models.FloatField(u'价格')
    img = models.ImageField(u'图片',upload_to='photos/%Y/%m/%d', blank=True)
    
    class Meta:
        verbose_name = u'菜肴'
        verbose_name_plural = u'菜肴'
        
    def __unicode__(self):
        return u"%s"%unicode(self.name)
        
class Order(models.Model):
    user = models.ForeignKey(User, verbose_name=u'用户')
    course = models.ForeignKey(Course, verbose_name=u'菜肴')
    dt = models.DateTimeField(u'订餐时间', auto_now=True)
    desc = models.CharField(u'备注', max_length=512)
    payed = models.BooleanField(u'是否已付款', default=False)
    
    class Meta:
        verbose_name = u'订单'
        verbose_name_plural = u'订单'
        
    def __unicode__(self):
        return "%s(%s) %s - %s"%(self.course.resta.name, self.course.resta.phone, self.user.last_name, self.course.name)
    
class GuestBook(models.Model):
    msg = models.TextField(u'留言',max_length=2000)
    user = models.ForeignKey(User, verbose_name=u'用户')
    
    def __unicode__(self):
        return user.last_name + truncate_zhwords(self.msg,10)
    
    class Meta:
        verbose_name_plural = u'留言'